package unit;

import java.util.Comparator;

import junit.framework.TestCase;

import com.google.code.netcheckin.aprs.Station;
import com.google.code.netcheckin.util.StationCallCollator;
import com.google.code.netcheckin.util.StationCallSuffixCollator;

public class UStationCallSuffixCollator extends TestCase {

	public static final String CALL_LOW 	= "KZ9JHU";
	public static final String CALL_MEDIUM	= "KC9JLU";
	public static final String CALL_HIGH	= "KA9TLH";

	protected Station stnLow;
	protected Station stnMedium;
	protected Station stnHigh;

	protected Comparator comp;

	public UStationCallSuffixCollator(String name) {
		super(name);
	}

	public void setUp() {
		stnLow = new Station();
		stnLow.setCallsign(CALL_LOW);
		stnMedium = new Station();
		stnMedium.setCallsign(CALL_MEDIUM);
		stnHigh = new Station();
		stnHigh.setCallsign(CALL_HIGH);
		comp = new StationCallSuffixCollator();
	}

	public void tearDown() {
		stnLow = null;
		stnMedium = null;
		stnHigh = null;
	}

	public void testAASwapPrefixSuffix() {
		TestStationCallSuffixCollator tscsc = new TestStationCallSuffixCollator();
		String answer = tscsc.testSwapPrefixSuffix(CALL_HIGH);
		assertEquals("a wrong simple", "TLH KA9", answer);

		answer = tscsc.testSwapPrefixSuffix("KB9YVI-10");
		assertEquals("b wrong simple", "YVI-10 KB9", answer);
	}

	public void testABGetCallsign() {
		TestStationCallSuffixCollator tscsc = new TestStationCallSuffixCollator();
		String answer = tscsc.testGetCallsign(stnMedium);
		assertEquals("wrong answer", "JLU KC9", answer);
	}

	public void testABEqual() {
		assertEquals("wrong answer", 0, comp.compare(stnLow, stnLow));
	}

	public void testACLess() {
		assertEquals("wrong answer", -1, comp.compare(stnLow, stnMedium));
	}

	public void testADGreater() {
		assertEquals("wrong answer", 1, comp.compare(stnHigh, stnMedium));
	}

	public void testAEEqualMethod() {
		StationCallSuffixCollator scc = new StationCallSuffixCollator();
		StationCallSuffixCollator scd = new StationCallSuffixCollator();
		assertTrue("fail equals", scc.equals(scd));
		assertFalse("fail obj", scc.equals(this));
		assertFalse("fail parent", scc.equals(new StationCallCollator()));
		
	}

		/** Expose protected methods. */

	public class TestStationCallSuffixCollator 
					extends StationCallSuffixCollator {
		public TestStationCallSuffixCollator() {
			super();
		}
		public String testGetCallsign(Station stn) {
			return getCallsign(stn);
		}
		public String testSwapPrefixSuffix(String callsign) {
			return swapPrefixSuffix(callsign);
		}
	}

}
